package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.JsonTools;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.activitity.InfoActivity.MoreInfoActivity;
import com.wsc.wisdomchina.activitity.JieDaoTeSheActivity;
import com.wsc.wisdomchina.activitity.JuWeiXinXiActivity;
import com.wsc.wisdomchina.activitity.LifeServerActivity;
import com.wsc.wisdomchina.activitity.LivingExpensesActivity;
import com.wsc.wisdomchina.activitity.PageInfoDetailActivity;
import com.wsc.wisdomchina.activitity.PeripheralSearchActivity;
import com.wsc.wisdomchina.activitity.ReceptionCenterActivity;
import com.wsc.wisdomchina.activitity.ShangjiaCuXiaoActivity;
import com.wsc.wisdomchina.activitity.fourmodule.CompanyInfoActivity;
import com.wsc.wisdomchina.activitity.fourmodule.FloorEventActivity;
import com.wsc.wisdomchina.activitity.fourmodule.FloorInfoActivity;
import com.wsc.wisdomchina.activitity.fourmodule.HelpOldManActivity;
import com.wsc.wisdomchina.activitity.fourmodule.PeopleControlActivity;
import com.wsc.wisdomchina.activitity.introduction.BriefIntroductionActivity;
import com.wsc.wisdomchina.activitity.samemodule.InfoAndActivityListActivity;
import com.wsc.wisdomchina.activitity.samemodule.InfoAndListActivity;
import com.wsc.wisdomchina.activitity.wisdomParty.PartyActivity;
import com.wsc.wisdomchina.activitity.wisdomParty.PartyLoginActivity;
import com.wsc.wisdomchina.constant.Constant;
import com.wsc.wisdomchina.education.activity.EducationActivity;
import com.wsc.wisdomchina.houselease.activity.HouseLeaseActivity;
import com.wsc.wisdomchina.javaBean.MyShowItemListBean;
import com.wsc.wisdomchina.javaBean.wisdomParty.PartyUserBean;
import com.wsc.wisdomchina.jobhunt.activity.JobHuntActivity;
import com.wsc.wisdomchina.notice.activity.AnnouncementListActivity;
import com.wsc.wisdomchina.welfare.activity.WelfareEventActivity;

import java.util.List;

public class IndexBaiShiTongAdapter extends BaseAdapter {

    private Context context;
    private List<MyShowItemListBean> objects;
    private LayoutInflater mInflater;
    private String cidnumber;

    public IndexBaiShiTongAdapter(Context context,List<MyShowItemListBean> objects,String cidnumber) {
        this.context = context;
        this.objects = objects;
        this.cidnumber = cidnumber;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public MyShowItemListBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        if (position%2==0)
        {
            return 0;
        }
        return 1;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            convertView = mInflater.inflate(R.layout.item_indexbaishitonganother, null);
        ViewHolder holder = new ViewHolder(convertView);
        bindListItem(holder, position);//控制视图显示数据

        return convertView;
    }

    //控制视图显示数据
    private void bindListItem(ViewHolder holder, final int pos) {
        try {
            final MyShowItemListBean myShowItemListBean=getItem(pos);
            final MyShowItemListBean.MenuserverBean menuserverBean=myShowItemListBean.getMenuserver();
            if(menuserverBean!=null)
            {
                String subTitle=menuserverBean.getSubtitle();
                if(subTitle!=null)
                    holder.tv_desc.setText(subTitle);
                holder.tv_name.setText(menuserverBean.getName());
                Glide.with(context).load(menuserverBean.getIcon())
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(holder.iv_dian);
                holder.layout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String menuId=myShowItemListBean.getMenuId();
                        if(menuId.equals("-1"))
                        {
                            //置空不处理
                        }else {
                            if(menuId.equals("0"))
                            {
                                //生活缴费
                                Intent intent = new Intent(context, LivingExpensesActivity.class);
                                intent.putExtra("name", menuserverBean.getName());
                                intent.putExtra("cid",cidnumber);
                                context.startActivity(intent);
                            }else if(menuId.equals("1"))
                            {
                                // 百姓监督
                                Intent intent = new Intent(context, PeopleControlActivity.class);
                                intent.putExtra("name", menuserverBean.getName());
                                intent.putExtra("cid", cidnumber);
                                context.startActivity(intent);
                            }else
                            {
                                int specialType=menuserverBean.getSpecialType();
                                String templeType=menuserverBean.getTempletType();
                                String isLast=menuserverBean.getIsLast();
                                String name=menuserverBean.getName();
                                if(specialType==0 ||specialType==3 ||specialType==5)
                                {
                                    String shortName=menuserverBean.getShortName();
                                    //普通菜单
            //                        else if(nameModule.equals("关心青少年"))
            //                        {
            //                            Intent intent=new Intent(context, CareTeenagersActivity.class);
            //                            intent.putExtra("cid",cidNumber);
            //                            startActivity(intent);
            //                        }
                                    if (shortName.equals("shjf")) {
                                        //生活缴费
                                        Intent intent = new Intent(context, LivingExpensesActivity.class);
                                        intent.putExtra("name", name);
                                        intent.putExtra("cid", cidnumber);
                                        context.startActivity(intent);
                                    }else if (shortName.equals("sjcx")) {
                                        //商家促销
                                        Intent intent = new Intent(context, ShangjiaCuXiaoActivity.class);
                                        intent.putExtra("id", cidnumber);
                                        intent.putExtra("name", name);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("lyxx")) {
                                        //楼宇信息
                                        Intent intent = new Intent(context, FloorInfoActivity.class);
                                        intent.putExtra("name", "楼宇搜索");
                                        intent.putExtra("id", cidnumber);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("qzzp")) {//求职招聘
                                        Intent intent = new Intent(context, JobHuntActivity.class);
                                        intent.putExtra("name", "求职招聘");
                                        intent.putExtra("id", cidnumber);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("fwzl")) {//房屋租赁
                                        Intent intent = new Intent(context, HouseLeaseActivity.class);
                                        intent.putExtra("name", "房屋租赁");
                                        intent.putExtra("id", cidnumber);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("jypx")) {//教育培训
                                        Intent intent = new Intent(context, EducationActivity.class);
                                        intent.putExtra("name", "教育培训");
                                        intent.putExtra("id", cidnumber);
                                        context.startActivity(intent);
                                    }else if (shortName.equals("qyxx")) {
                                        //企业信息
                                        Intent intent = new Intent(context, CompanyInfoActivity.class);
                                        intent.putExtra("name", "企业搜索");
                                        intent.putExtra("id", cidnumber);
                                        context.startActivity(intent);
                                    }else if (shortName.equals("bsck")) {
                                        //受理中心
                                        Intent intent = new Intent(context, ReceptionCenterActivity.class);
                                        intent.putExtra("id", cidnumber);
                                        intent.putExtra("name", name);
                                        context.startActivity(intent);
                                    }
                                    else if (shortName.equals("zlfw")) {
                                        //助老服务
                                        Intent intent = new Intent(context, HelpOldManActivity.class);
                                        intent.putExtra("name", name);
                                        intent.putExtra("cid", cidnumber);
                                        intent.putExtra("idmodule", menuId);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("zcfw")) {
                                        //助残服务
                                        Intent intent = new Intent(context, HelpOldManActivity.class);
                                        intent.putExtra("name", name);
                                        intent.putExtra("cid", cidnumber);
                                        intent.putExtra("idmodule", menuId);
                                        context.startActivity(intent);
                                    } else if (shortName.equals("bxjd")) {
                                        // 百姓监督
                                        Intent intent = new Intent(context, PeopleControlActivity.class);
                                        intent.putExtra("name", name);
                                        intent.putExtra("cid", cidnumber);
                                        context.startActivity(intent);
                                    }
//                                  else if (name.equals("智慧党建")) {
//                                        String jsonMessage = Tools.getSharedPreferencesStrings(Constant.SharePreferencePartyUserInfo, "", context);
//                                        if (jsonMessage.equals("")) {
//                                            // 智慧党建
//                                            Intent intent = new Intent(context, PartyLoginActivity.class);
//                                            intent.putExtra("name", name);
//                                            intent.putExtra("cid", cidnumber);
//                                            context.startActivity(intent);
//                                        } else {
//                                            PartyUserBean partyUserBean = JsonTools.jsonStringToObject(jsonMessage, PartyUserBean.class);
//                                            Intent intent = new Intent(context, PartyActivity.class);
//                                            intent.putExtra("pId", partyUserBean.getId());
//                                            intent.putExtra("cId", cidnumber);
//                                            context.startActivity(intent);
//                                        }
//                                    }

                                }else if(specialType==1)
                                {
                                    //资讯、活动类菜单
                                    if(isLast.equals("0"))
                                    {
                                        //根据父id查询子级
                                        Intent intent=new Intent(context, InfoAndActivityListActivity.class);
                                        intent.putExtra("cid",cidnumber);
                                        intent.putExtra("menuId",myShowItemListBean.getMenuId());
                                        intent.putExtra("name",menuserverBean.getName());
                                        context.startActivity(intent);
                                    }else
                                    {
                                        //是最终菜单，无子菜单
                                        if(templeType.equals("0"))
                                        {
                                            //资讯
                                            //1,获取街道政务列表
                                            //2,获取街道政务详情
                                            Intent intent=new Intent(context, InfoAndListActivity.class);
                                            intent.putExtra("streetId",cidnumber);
                                            intent.putExtra("menuId",myShowItemListBean.getMenuId());
                                            intent.putExtra("isInfo",true);
                                            intent.putExtra("name",menuserverBean.getName());
                                            context.startActivity(intent);
                                        }else {
                                            //活动
                                            //1,获取街道活动列表
                                            //2,获取活动详情
                                            Intent intent=new Intent(context, InfoAndListActivity.class);
                                            intent.putExtra("streetId",cidnumber);
                                            intent.putExtra("menuId",myShowItemListBean.getMenuId());
                                            intent.putExtra("isInfo",false);
                                            intent.putExtra("name",menuserverBean.getName());
                                            context.startActivity(intent);
                                        }
                                    }
                                }else if(specialType==4)
                                {
                                    //资讯管理
                                    Intent intent1=new Intent(context, MoreInfoActivity.class);
                                    context.startActivity(intent1);
                                }
                            }
                        }
                    }
                });
            }

        }catch (Exception e)
        {

        }

    }

    public class ViewHolder {
        private ImageView iv_dian;//标题
        private TextView tv_name;//来源
        private TextView tv_desc;//时间
        private RelativeLayout layout;

        public ViewHolder(View view) {
            iv_dian = (ImageView) view.findViewById(R.id.iv_dian);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_desc = (TextView) view.findViewById(R.id.tv_desc);
            layout = (RelativeLayout) view.findViewById(R.id.layout);
        }
    }

}
